#include "Sampler.h"
#include "SamplerWrapper.h"
#include "NDArray.h"

using namespace std;

extern "C"
{
	void *Sampler_new( unsigned int rings, unsigned int *ringsRadius, unsigned int *samplesPerRing )
	{
		return (void*) new Sampler( rings, ringsRadius, samplesPerRing );
	}

	void Sampler_get_point( void* sampler, double *data, unsigned int rows, unsigned int columns, unsigned int centerX, unsigned int centerY, double *result )
	{
		CVGreyc::NDArray::CArray<double> tmp( data, rows, columns );
		CVGreyc::NDArray::CArray<double> out( result, ((Sampler*) sampler)->nbSamples() );
		((Sampler*) sampler)->operator()( tmp, centerX, centerY, out );
	}

	void Sampler_get_points( void* sampler, double *data, unsigned int rows, unsigned int columns, unsigned int *xy, unsigned int nbXY, double *result)
	{
		CVGreyc::NDArray::CArray<double> tmp( data, rows, columns );
		CVGreyc::NDArray::CArray<double> out( result, nbXY, ((Sampler*) sampler)->nbSamples() );
		CVGreyc::NDArray::CArray<unsigned int> xy_(xy,nbXY,2);
		((Sampler*) sampler)->operator()( tmp, xy_, out );
	}
		
	void Sampler_get_image( void* sampler, double *data, unsigned int dataRows, unsigned int dataCols, double *result )
	{
		CVGreyc::NDArray::CArray<double> tmp( data, dataRows, dataCols );
		CVGreyc::NDArray::CArray<double> out( result,
						      Sampler_getXRes( sampler, data, dataRows, dataCols ),
						      Sampler_getYRes( sampler, data, dataRows, dataCols ),
						      Sampler_nbSamples( sampler ) );
		((Sampler*) sampler)->operator()( tmp, out );
	}
		
	unsigned int Sampler_getXRes( void *sampler, double *data, unsigned int dataRows, unsigned int dataCols )
	{
		CVGreyc::NDArray::CArray<double> tmp( data, dataRows, dataCols );
		return ((Sampler*) sampler)->getXRes(tmp);
	}
		
	unsigned int Sampler_getYRes( void *sampler, double *data, unsigned int dataRows, unsigned int dataCols )
	{
		CVGreyc::NDArray::CArray<double> tmp( data, dataRows, dataCols );
		return ((Sampler*) sampler)->getYRes(tmp);
	}

	unsigned int Sampler_nbSamples( void *sampler )
	{
		return ((Sampler*) sampler)->nbSamples();
	}

	void Sampler_delete( void *sampler )
	{
		delete (Sampler*) sampler;
	}
}
